package com.qiaoyanqing.ximalaya.discovermodule.discover_adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.qiaoyanqing.ximalaya.R;
import com.qiaoyanqing.ximalaya.discovermodule.discover_entity.BroadcastResultEntity;
import com.squareup.picasso.Picasso;

import java.util.List;

/**
 * Created by Administrator on 2016/12/8.
 */

public class BroadcastTypeAdapter extends RecyclerView.Adapter <BroadcastTypeAdapter.MyViewHolder>{
    private Context context;
    private List<BroadcastResultEntity> list;

    public BroadcastTypeAdapter(Context context, List<BroadcastResultEntity> list) {
        this.context = context;
        this.list = list;
    }

    @Override
    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.broadcast_recycler_item, parent, false);
        MyViewHolder holder = new MyViewHolder(view);
        return holder;
    }

    @Override
    public void onBindViewHolder(MyViewHolder holder, int position) {
        holder.broacast_playCount.setText(list.get(position).getRadioPlayCount()/1000+"万");
        holder.broadcast_name.setText(list.get(position).getRname());
        holder.broadcast_programName.setText("正在直播:"+list.get(position).getProgramName());
        Picasso.with(context).load(list.get(position).getRadioCoverSmall()).into(holder.broadcast_iv);
    }

    @Override
    public int getItemCount() {
        Log.d("=====", "getItemCount: "+list.size());
        return list.size();
    }

    static class MyViewHolder extends RecyclerView.ViewHolder{

        private ImageView broadcast_iv;
        private TextView broadcast_name,broadcast_programName,broacast_playCount;
        public MyViewHolder(View itemView) {
            super(itemView);
            broadcast_iv = (ImageView) itemView.findViewById(R.id.broadcase_iv);
            broadcast_name = (TextView) itemView.findViewById(R.id.broadcase_name);
            broadcast_programName = (TextView) itemView.findViewById(R.id.broadcast_programName);
            broacast_playCount = (TextView) itemView.findViewById(R.id.broadcast_playCount);
        }
    }
}
